package com.qingyun.framework.web.service;

import com.alibaba.fastjson.JSONObject;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @Classname SmsService
 * @Author dyh
 * @Date 2021/9/16 19:09
 */
@Service
@Slf4j
public class SmsService {

	@Autowired
	private Client client;


	public Boolean sendSms(String phone,String code) throws Exception {
		SendSmsRequest sendSmsRequest = new SendSmsRequest();
		sendSmsRequest.setSignName("拓流者");
		sendSmsRequest.setTemplateCode("SMS_225630224");
		sendSmsRequest.setPhoneNumbers(phone);
		HashMap<String, String> map = new HashMap<>();
		map.put("code",code);
		sendSmsRequest.setTemplateParam(JSONObject.toJSONString(map));
		SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
		log.debug(JSONObject.toJSONString(sendSmsRequest));
		if (sendSmsResponse.getBody().getCode().equalsIgnoreCase("OK")) {
			return true;
		}
		return false;
	}

}
